package com.hsylient.javase.chapter11.threadlocal;

import com.hsylient.javase.common.enmu.Status;
import lombok.Data;
import lombok.NoArgsConstructor;

public class ThreadLocalTest2 {

    private static final ThreadLocal<Employee> USER_INFO = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            int finalI = i;
            Thread thread = new Thread(() -> {
                Employee employee = new Employee();
                employee.setId((long) finalI);
                USER_INFO.set(employee);
            });
            thread.setName(String.valueOf(i));
            thread.start();

            System.out.println(thread.getName() + "线程获得变量：" + USER_INFO.get());

        }
        Thread.sleep(100000L);
    }


    @Data
    @NoArgsConstructor
    private static class Employee {

        private Long id;

        private String name;

        private Integer age;

        private Double salary;

        private Status status;
    }

}
